package com.sync.syncmasterdata.baidu.controller;

import com.sync.syncmasterdata.baidu.service.BaiduService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/baiduService")
@Slf4j
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    @PostMapping("/simnetService")
    @ResponseBody
    public Float getSimResult(@RequestBody Map<String,Object> map) {
        log.info("-------------map:{}", map.toString());
        try {
            if (StringUtils.isBlank(map.get("one").toString()) || StringUtils.isBlank(map.get("two").toString())) {
                return null;
            }
            Float result=baiduService.simnetService(map.get("one").toString(), map.get("two").toString());
            return result;
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
}
